<template>
	<view>
		<view id="main">
			<view class="in-order-summary">
				<view>
					<image :src="swichLogo()" style="width: 110rpx;height: 110rpx;border-radius: 60rpx;"></image>
				</view>
				<view style="margin-top: 15rpx;margin-left: 20rpx;">
					<view style="font-size: 19px;">
						<span>¥<span>{{money}}</span></span>
					</view>
					<view style="font-size: 11px;color: #c6c5c5;">
						<span>携联品牌共享</span>
					</view>
				</view>
			</view>
			<view class="btn-line">
				<view class="confirm-box" @click="rugu()" id="rugu">确定支付
					<span style="margin-left: 10px;font-size: 17px;font-weight: 500;">
						<span>¥<span>{{money}}</span></span>
					</span>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ppid:'',	//品牌ID
				money:0.00,	//入股金额
				logo:'',	//品牌logo
				ddhao:'',	//品牌入股订单号
			}
		},
		onLoad(opt) {
			this.ppid = opt.ppid;
			this.money = opt.money;
			this.logo = opt.logo;
		},
		methods: {
			swichLogo(){
				return this.host+"/image/pingpaiLogo/"+this.logo
			},
			rugu(){
				console.log("点击确定品牌入股了")
				let userid = uni.getStorageSync('usersId');
				let openId = uni.getStorageSync('openId');
				this.$http.get('/ppOrderPay/pinpairuguWeixinPayxcx',{
					userId:userid,
					ppid:this.ppid,
					money:this.money,
					openId:openId
				}).then(res => {
					console.log(res.data)
					if(res.data.code==200){
						this.ddhao = res.data.data.ddhao;
						this.pay(res)//调用微信支付
					}else{
						this.$u.toast(res.data.msg)
					}
				})
			},
			//支付
			pay(res){
				let that = this;
				uni.requestPayment({
					appid: res.data.data.appId,  			// AppId，注意微信小程序、公众号 AppId 可能不一致
					nonceStr: res.data.data.nonceStr, 		// 随机字符串
					package: res.data.data.package,         // 固定值
					signType: res.data.data.signType,		// 签名类型
					timeStamp: res.data.data.timeStamp,     // 时间戳（单位：秒）
					paySign:res.data.data.paySign,
					success(res) {
						uni.showToast({
							title: '支付成功',
							icon: 'success'
						});
						//支付成功修改订单状态
						that.$http.get('/ppOrderPay/pinpairugupayNotifyxcx',{
							orderId:that.ddhao,
							money:that.money
						}).then(res => {
							//支付成功，跳转页面
							uni.$emit('checkPinpaiUserInfo');
							uni.$emit('getPinpaiOrderByGroup');
							uni.navigateBack(2)
						})
					},
					fail(e) {
						uni.showToast({
							title: '支付失败',
							icon: 'error'
						});
					}
				})
			},
		}
	}
</script>

<style>
	.in-order-summary{
		height: 30%;
		background-color: white;
		display: flex;
		justify-content: center;
		padding: 20rpx 0 20rpx 0;
	}
	.confirm-box{
		margin: auto;
		margin-top: 16px;
		font-size: 15px;
		text-align: center;
		padding: 6px;
		width: 90%;
		border-radius: 10px;
		color: white;
		background-color: #f5ab2f;
	}
</style>
